package com.xtianzhuang.www.utils;

import java.io.Serializable;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class Pagination implements Serializable {
	protected static final SerializerFeature[] serializerFeatures;
	private static final long serialVersionUID = 1L;
	public static final int MAX_PAGE_SIZE = 2000;
	public static final int MAX_RECODE_SIZE = 2147483647;
	private boolean batch;
	private boolean range;
	private boolean needCount = true;
	private boolean onlyCount = false;
	private int start;
	private int size;
	private int count;
	private int currPage;

	public Pagination() {
		this.range = true;
	}

	public Pagination(boolean batch) {
		this.setBatch(batch);
	}

	public Pagination setBatch(boolean batch) {
		this.batch = batch;
		if (batch) {
			this.range = true;
		}

		return this;
	}

	public Pagination setRange(int start, int size) {
		this.range = true;
		this.start = start;
		this.size = size;
		return this;
	}

	public boolean isBatch() {
		return this.batch;
	}

	public boolean isRange() {
		return this.range;
	}

	public boolean isNeedCount() {
		return this.needCount;
	}

	public Pagination setNeedCount(boolean needCount) {
		this.needCount = needCount;
		return this;
	}

	public int getCount() {
		return this.count;
	}

	public Pagination setCount(int count) {
		this.count = count;
		return this;
	}

	public int getStart() {
		return this.start;
	}

	public int getSize() {
		return this.size;
	}

	public int getCurrPage() {
		return this.currPage;
	}

	public Pagination setCurrPage(int currPage) {
		this.currPage = currPage;
		return this;
	}

	public boolean isOnlyCount() {
		return this.onlyCount;
	}

	public Pagination setOnlyCount(boolean onlyCount) {
		this.onlyCount = onlyCount;
		return this;
	}

	public String toString() {
		return JSON.toJSONString(this, serializerFeatures);
	}

	static {
		serializerFeatures = new SerializerFeature[]{SerializerFeature.WriteDateUseDateFormat};
	}
}